#ifndef __BAMBU_H__
#define __BAMBU_H__
#include <Arduino.h>
#include <ArduinoJson.h>
#include <PubSubClient.h>
#include <WiFiClientSecure.h>

union RunningState {
    uint8_t all;
    struct {
        uint8_t unload      : 1; //退料指令
        uint8_t motor       : 1; //电机
        uint8_t unload_done : 1; //退料完成
        uint8_t load        : 1; //上料指令
        uint8_t load_done   : 1; //上料完成
        uint8_t err_load    : 1; //缠料检查
        uint8_t reserved : 2;
    } bit;
};
typedef struct{
    String sequenceId;
    String amsStatus;
    String printError;
    String hwSwitchState;
    String gcodeState;
    String mcPercent;
    String mcRemainingTime;
    String nextFilament;
    String lastFilament;
}BAMBU_DATA;

typedef struct{
    String mqtt_user;
    String mqtt_id;
    String mqtt_broker;
    String mqtt_password;
    String device_serial;
    String topic_subscribe;
    String topic_publish;
    unsigned int RenewTime;
    boolean led;
    void (*callback)(char* topic, byte* payload, unsigned int length);
}BAMBU_CFG;

typedef struct{
    String resume;
    String unload;
    String load;
    String done;
    String pause;
    String clear;
    String status;
    String ledON;
    String ledOFF;
}BAMBU_COMMAND;

typedef struct{
    void (*connect)(void);
    void (*debugCtrl)(String);
    void (*getdata)(byte* payload, unsigned int length);
    void (*printdata)(void);
    void (*work)(void);
}BAMBU_OPS;

typedef struct{
    WiFiClientSecure* WifiClient;
    PubSubClient* Client;
    BAMBU_COMMAND* comm;
    BAMBU_DATA* data;
    BAMBU_CFG* cfg;
    BAMBU_OPS* ops;

}BAMBU;

extern BAMBU bambu;

#endif //__BAMBU_H__
